/* 
 * File:   RandomGenerator.cpp
 * Author: fibrizo
 * 
 * Created on 6 de junio de 2014, 20:40
 */

#include "server_RandomGenerator.h"
#include <cstdlib>
#include <iostream>
#include <chrono>
#include <string>
#include <ctime>
#include <ratio>
#include <sstream>
#include <vector>
#include <exception>
#include <stdexcept>
#include <random>

using std::vector;
//using namespace std::chrono;
using std::cout;
using std::endl;
using std::stringstream;
using std::string;
using std::stoi;

RandomGenerator::RandomGenerator() {
}

int RandomGenerator::generate(int min, int max) {
    /*
    high_resolution_clock::time_point t1 = high_resolution_clock::now();
    vector<string>* perdedorDeTiempo = new vector<string>();
    delete perdedorDeTiempo;
    high_resolution_clock::time_point t2 = high_resolution_clock::now();
    duration<double> time_span = duration_cast<duration<double>>(t2 - t1);    
    stringstream ss;
    ss << time_span.count()*1000000;
    string s;
    s = ss.str();
    stringstream sss;
    sss << s[0];
    int randomNumber = 0;
    try {
        randomNumber = stoi((sss.str()), NULL, 10);
    } catch (std::invalid_argument e) {
    }
    cout << randomNumber << endl;
    return (min + randomNumber % (max - min + 1));*/
    
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

    std::minstd_rand0 generator (seed);  // minstd_rand0 is a standard linear_congruential_engine
    int randomNumber = (min + generator() % (max - min + 1));
    cout << randomNumber << endl;
    return randomNumber;

}

RandomGenerator::RandomGenerator(const RandomGenerator& orig) {
}

RandomGenerator::~RandomGenerator() {
}

